# coding= utf-8
import pygame
from pygame.sprite import Group


from settings import Settings
from game_stats import GameStats
from scoreboard import Scoreboard
from button import Button
from hunter import Ship
import game_functions as gf

def run_game():
    # 初始化 pygame 所拥有组件的检查操作
    pygame.init()
    # 传入全局设置参量
    ai_settings = Settings()
    # 根据传入的ai_settings 引入具体数值赋于屏幕大小设定
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    # 设置窗口抬头名字
    pygame.display.set_caption(" Happy Childrens'day ")
    
    # 设置按钮： 触发事件 + 屏幕开启 + 字符串为按钮名字
    play_button = Button(ai_settings, screen, "Bears ???")
    
    # 创建一个实例来存储游戏数据和记分牌.
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)
    
    # 设置背景颜色，貌似已经在Setting.py模块中涉及到所以没用到
    bg_color = (230, 230, 230)
    
    # 造光头强 一系列子弹 一群熊
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()
    
    # 创建熊队.
    gf.create_fleet(ai_settings, screen, ship, aliens)

    # 开始游戏的主循环
    while True:
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship,
            aliens, bullets)
        
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
                bullets)
            gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens,
                bullets)
        
        gf.update_screen(ai_settings, screen, stats, sb, ship, aliens,
            bullets, play_button)

run_game()